ccR.Add_Rotation(
	1,
	"CC_Discipline_Levelling",
	"10-xx\n\nStill in development.",
	"CC_Discipline_Talents", "CC_Discipline_Abilities",
	"CC_Discipline_Features",
	"CC_Discipline_Setup"
)
function CC_Discipline_Levelling()

	if ccR.Player.Is.ChannelingSpell(PENANCE) then return end

	if ccR.Var("Desperate_Prayer") then ccR.Priest.Talent.Desperate_Prayer(ccR.Var("Desperate_Prayer_Count")) end


	--if ccR.Player.Is.InDungeon() then
		-- Healing
		local Tank
		local SecondLowestHP = "player"
		local LowestHP = "player"
		for i = 1, #ccR_Friendly do
			local unit = ccR_Friendly[i]
			-- Preliminary Check on unit
			if ccR.Unit.Exists(unit)
			and ccR.Unit.Is.Alive(unit)
			and ccR.Unit.Is.APlayer(unit)
			and ccR.Unit.Distance(unit, "player") <= 44
			then
				-- Set Tank
				if ccR.Unit.Is.Tank(unit) then Tank = unit end
				-- Set Lowest and Second Lowest
				if ccR.Unit.Health(unit) < ccR.Unit.Health(LowestHP) then
					SecondLowestHP = LowestHP
					LowestHP = unit
				elseif ccR.Unit.Health(vUnit) == ccR.Unit.Health(LowestHP) then
					if UnitHealthMax(vUnit) < UnitHealthMax(LowestHP) then
						SecondLowestHP = LowestHP
						LowestHP = vUnit
					else
						SecondLowestHP = vUnit
					end
				end
			end
		end
		-- Archangel
		if ccR.Var("Archangel") then ccR.Priest.Discipline.Archangel(ccR.Var("Archangel_Count")) end
		-- Fear Ward
		if ccR.Var("Fear_Ward") then ccR.Priest.Discipline.Fear_Ward(Tank) end
		-- Purify
		if ccR.Var("Purify") then
			ccR.Priest.Discipline.Purify(Tank)
			ccR.Priest.Discipline.Purify(LowestHP)
			ccR.Priest.Discipline.Purify(SecondLowestHP)
		end
		--[[
			22 Purify
			24 Fade
			26 Dispel Magic
		]]
		if ccR.Player.Level() >= 15 
		and ccR.Player.Level() <= 33 
		then
			ccR.Priest.Discipline.PWS(Tank, 99)
			ccR.Priest.Discipline.PWS(LowestHP, 80)
			ccR.Priest.Discipline.PWS(SecondLowestHP, 85)

			ccR.Priest.Discipline.Penance(Tank, 75)
			ccR.Priest.Discipline.Penance(LowestHP, 50)
			ccR.Priest.Discipline.Penance(SecondLowestHP, 60)

			ccR.Priest.Discipline.Flash_Heal(Tank, 90)
			ccR.Priest.Discipline.Flash_Heal(LowestHP, 85)
			ccR.Priest.Discipline.Flash_Heal(SecondLowestHP, 90)
		end
		--[[
			34 Heal
		]]
		if ccR.Player.Level() >= 34 
		and ccR.Player.Level() <= 37 
		then
			ccR.Priest.Discipline.PWS(Tank, 99)
			ccR.Priest.Discipline.PWS(LowestHP, 80)
			ccR.Priest.Discipline.PWS(SecondLowestHP, 85)

			ccR.Priest.Discipline.Penance(Tank, 75)
			ccR.Priest.Discipline.Penance(LowestHP, 50)
			ccR.Priest.Discipline.Penance(SecondLowestHP, 60)

			ccR.Priest.Discipline.Flash_Heal(Tank, 60)
			ccR.Priest.Discipline.Flash_Heal(LowestHP, 55)
			ccR.Priest.Discipline.Flash_Heal(SecondLowestHP, 60)

			ccR.Priest.Discipline.Heal(Tank, 90)
			ccR.Priest.Discipline.Heal(LowestHP, 85)
			ccR.Priest.Discipline.Heal(SecondLowestHP, 90)
		end
		--[[
			38 Atonement
			42 Shadowfiend
		]]
		if ccR.Player.Level() >= 38 
		and ccR.Player.Level() <= 45 
		then
			ccR.Priest.Discipline.PWS(Tank, 100, true)
			ccR.Priest.Discipline.PWS(LowestHP, 80)
			ccR.Priest.Discipline.PWS(SecondLowestHP, 85)

			ccR.Priest.Discipline.Penance(Tank, 60)
			ccR.Priest.Discipline.Penance(LowestHP, 45)
			ccR.Priest.Discipline.Penance(SecondLowestHP, 50)

			-- Rely on Atonement DPS in combat with a Target
			if ccR.Player.Is.In.Combat()
			and ccR.Target.Is.Attackable()
			then
				ccR.Priest.Discipline.Flash_Heal(Tank, 75)
				ccR.Priest.Discipline.Flash_Heal(LowestHP, 50)
				ccR.Priest.Discipline.Flash_Heal(SecondLowestHP, 55)
			else
				-- Not in combat, Heal is too weak, rely on Flash Heal
				ccR.Priest.Discipline.Flash_Heal(Tank, 99)
				ccR.Priest.Discipline.Flash_Heal(LowestHP, 90)
				ccR.Priest.Discipline.Flash_Heal(SecondLowestHP, 90)
			end
		end
		--[[
			46 Prayer of Healing
			50 Archangel
			54 Fear Ward
			58 Pain Suppression
		]]

		if ccR.Player.Level() >= 46 
		and ccR.Player.Level() <= 67 
		then
			ccR.Priest.Discipline.Pain_Suppression(Tank, 40)
			ccR.Priest.Discipline.Pain_Suppression(LowestHP, 30)
			ccR.Priest.Discipline.Pain_Suppression(SecondLowestHP, 30)

			ccR.Priest.Discipline.PWS(Tank, 100, true)
			ccR.Priest.Discipline.PWS(LowestHP, 80)
			ccR.Priest.Discipline.PWS(SecondLowestHP, 85)

			ccR.Priest.Discipline.Penance(Tank, 60)
			ccR.Priest.Discipline.Penance(LowestHP, 45)
			ccR.Priest.Discipline.Penance(SecondLowestHP, 50)

			if ccR.Player.Has.Talent(SURGE_OF_LIGHT)
			and ccR.Player.Has.Buff(SURGE_OF_LIGHT_BUFF)
			then
				ccR.Priest.Discipline.Flash_Heal(Tank, 99)
				ccR.Priest.Discipline.Flash_Heal(LowestHP, 95)
				ccR.Priest.Discipline.Flash_Heal(SecondLowestHP, 95)
			end

			-- Rely on Atonement DPS in combat with a Target
			if ccR.Player.Is.In.Combat()
			and ccR.Target.Is.Attackable()
			then
				ccR.Priest.Discipline.Flash_Heal(Tank, 75)
				ccR.Priest.Discipline.Flash_Heal(LowestHP, 50)
				ccR.Priest.Discipline.Flash_Heal(SecondLowestHP, 55)
			else
				-- Not in combat, Heal is too weak, rely on Flash Heal
				ccR.Priest.Discipline.Flash_Heal(Tank, 99)
				ccR.Priest.Discipline.Flash_Heal(LowestHP, 90)
				ccR.Priest.Discipline.Flash_Heal(SecondLowestHP, 90)
			end

			ccR.Priest.Discipline.Prayer_of_Healing(Tank, 70, 3)
			ccR.Priest.Discipline.Prayer_of_Healing(LowestHP, 70, 3)
			ccR.Priest.Discipline.Prayer_of_Healing(SecondLowestHP, 70, 3)
		end
		--[[
			68 Prayer of Mending
			70 PW:Barrier
			72 Mass Dispel
		]]
		if ccR.Player.Level() >= 68 
		and ccR.Player.Level() <= 100 
		then
			ccR.Priest.Discipline.Pain_Suppression(Tank, 40)
			ccR.Priest.Discipline.Pain_Suppression(LowestHP, 30)
			ccR.Priest.Discipline.Pain_Suppression(SecondLowestHP, 30)

			ccR.Priest.Discipline.Power_Word_Barrier(Tank, 40, 2)
			ccR.Priest.Discipline.Power_Word_Barrier(LowestHP, 40, 2)
			ccR.Priest.Discipline.Power_Word_Barrier(SecondLowestHP, 40, 2)

			ccR.Priest.Discipline.PWS(Tank, 100, true)
			ccR.Priest.Discipline.PWS(LowestHP, 80)
			ccR.Priest.Discipline.PWS(SecondLowestHP, 85)

			ccR.Priest.Discipline.Prayer_of_Mending(Tank, 100)
			ccR.Priest.Discipline.Prayer_of_Mending(LowestHP, 60)
			ccR.Priest.Discipline.Prayer_of_Mending(SecondLowestHP, 60)

			ccR.Priest.Discipline.Penance(Tank, 60)
			ccR.Priest.Discipline.Penance(LowestHP, 45)
			ccR.Priest.Discipline.Penance(SecondLowestHP, 50)

			if ccR.Player.Has.Talent(SURGE_OF_LIGHT)
			and ccR.Player.Has.Buff(SURGE_OF_LIGHT_BUFF)
			then
				ccR.Priest.Discipline.Flash_Heal(Tank, 99)
				ccR.Priest.Discipline.Flash_Heal(LowestHP, 95)
				ccR.Priest.Discipline.Flash_Heal(SecondLowestHP, 95)
			end

			ccR.Priest.Discipline.Prayer_of_Healing(Tank, 70, 3)
			ccR.Priest.Discipline.Prayer_of_Healing(LowestHP, 70, 3)
			ccR.Priest.Discipline.Prayer_of_Healing(SecondLowestHP, 70, 3)
			
			-- Rely on Atonement DPS in combat with a Target
			if ccR.Player.Is.In.Combat()
			and ccR.Target.Is.Attackable()
			then
				ccR.Priest.Discipline.Flash_Heal(Tank, 75)
				ccR.Priest.Discipline.Flash_Heal(LowestHP, 50)
				ccR.Priest.Discipline.Flash_Heal(SecondLowestHP, 55)
			else
				-- Not in combat, Heal is too weak, rely on Flash Heal
				ccR.Priest.Discipline.Flash_Heal(Tank, 99)
				ccR.Priest.Discipline.Flash_Heal(LowestHP, 90)
				ccR.Priest.Discipline.Flash_Heal(SecondLowestHP, 90)
			end


		end		
	--end

	-- Fade on aggro
	if ccR.Player.Is.InDungeon() then if ccR.Var("Fade") then ccR.Priest.Discipline.Fade() end end
	-- PW:S on aggro
	if ccR.Var("PWS_OnAggro") then ccR.Priest.Feature.PWS() end
	-- SW:P All solo or before Atonement
	if ccR.Var("SWP_All") and (ccR.Player.Is.Solo() or ccR.Player.Level() <= 38) then ccR.Cast.Mass.Debuff(SHADOW_WORD_PAIN, "all", 40, false, 1) end

	if ccR.Target.Is.Attackable() then
		-- Mindbender/Shadowfiend
		if ccR.Var("Shadowfiend") then
			if ccR.Player.Has.Talent(MINDBENDER) then
				if ccR.Player.Level() >= 42 and ccR.Spell.CanAttack(MINDBENDER) then ccR.Cast.Attack(MINDBENDER) end
			else
				if ccR.Player.Level() >= 42 and ccR.Spell.CanAttack(SHADOWFIEND)  then ccR.Cast.Attack(SHADOWFIEND) end
			end
		end
		-- SW:P Target when solo or before Atonement
		if (ccR.Player.Is.Solo() or ccR.Player.Level() <= 38) and not ccR.Target.Has.MyDebuff(SHADOW_WORD_PAIN) and ccR.Spell.CanAttack(SHADOW_WORD_PAIN) then ccR.Cast.Debuff(SHADOW_WORD_PAIN) end
		-- Holy Fire
		if ccR.Player.Is.Facing("target") then
			if ccR.Player.Level() >= 18 and ccR.Spell.CanAttack(HOLY_FIRE) then ccR.Cast.Attack(HOLY_FIRE) end
		end
		if not ccR.Player.Is.Moving() 
		and ccR.Player.Is.Facing("target") 
		then
			-- Penance
			if ccR.Spell.CanAttack(PENANCE) then ccR.Cast.Attack(PENANCE) end
			-- Smite
			if ccR.Spell.CanAttack(SMITE) then ccR.Cast.Attack(SMITE) end
		end
	end
end